package com.jhhc.BDMS.System.Serivce.impl;

import com.jhhc.BDMS.System.Dao.BDMS_POWER_BMapper;
import com.jhhc.BDMS.System.Serivce.BDMS_POWER_BService;
import com.jhhc.BDMS.System.entity.BDMS_POWER_B;
import com.jhhc.utils.RedisUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (BdmsPowerB)表服务实现类
 *
 * @author makejava
 * @since 2024-08-21 10:03:10
 */
@Service
@RequiredArgsConstructor
public class BDMS_POWER_BServiceImpl implements BDMS_POWER_BService {
    @Resource
    private BDMS_POWER_BMapper powerMapper;

    private final RedisUtil redisTemplate;

    @Override
    public boolean queryAll() {
        List<BDMS_POWER_B> bdmsPowerBs = powerMapper.queryAll();
        if (bdmsPowerBs != null && !bdmsPowerBs.isEmpty()) {
            redisTemplate.setCacheList("token",bdmsPowerBs);
            redisTemplate.expire("token",72000L);
            return true;
        }else {
            return false;
        }
    }

    @Override
    public List<BDMS_POWER_B> queryAll(String token) {
        List<BDMS_POWER_B> bdmsPowerBs = redisTemplate.getCacheList(token);
        if (bdmsPowerBs == null || bdmsPowerBs.isEmpty()) {
            queryAll();
            bdmsPowerBs = redisTemplate.getCacheList("token");
        }
        return bdmsPowerBs;
    }
}
